package com.example.handler;

import com.example.pojo.KUser;
import com.example.service.common.IDataSynchronousService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;


/**
 * @author panghu
 * @version 1.0.0
 * @createTime 2023年09月09日 18:54:00
 * @Description  文档参考: https://github.com/NormanGyllenhaal/canal-client
 */
@Component
@Slf4j
@CanalTable(value = "kuser")
public class KUserHandler implements EntryHandler<KUser> {

    @Autowired
    private IDataSynchronousService redisSynServiceImpl;

    @Autowired
    private IDataSynchronousService elasticSynServiceImpl;

    @Override
    public void insert(KUser kUser) {
        log.info("【添加用户】信息是: {}", kUser);
        redisSynServiceImpl.insertData(kUser);
        elasticSynServiceImpl.insertData(kUser);
    }

    @Override
    public void update(KUser before, KUser after) {
        log.info("【修改之前】的用户信息是: {}",before);
        log.info("【修改之后】的用户信息是: {}",after);
        redisSynServiceImpl.updateData(before,after);
        elasticSynServiceImpl.updateData(before,after);
    }

    @Override
    public void delete(KUser kUser) {
        log.info("【删除用户】信息是: {}", kUser);
        redisSynServiceImpl.deleteData(kUser);
        elasticSynServiceImpl.deleteData(kUser);
    }

}
